﻿Imports System.Object
Imports VSModel
Imports Cls_Common
Imports System.IO
Imports System.Data
Partial Class FrontEnd_Control_Home_News
    Inherits System.Web.UI.UserControl
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            BindToGrid()
        End If
    End Sub
    Private Sub BindToGrid()
        Using Data As New VSEntities
            '1 tin lon
            'Add DomainName DUC 09-09-2014
            Dim p = (From q In Data.Contents Where q.Domain = DomainName And q.StatusId = 3 Order By q.PublishedDate Descending Select q).FirstOrDefault
            If Not p Is Nothing Then
                hplTitle.Text = p.Title
                hplTitle.CssClass = "title-thumbnail"
                hplTitle.NavigateUrl = MainDomain & "tin-tuc-chi-tiet/" & p.QueryString & "-" & p.Id & ".html"

                hplImage.CssClass = "pull-left"
                imgImage.ImageUrl = CookedImageURL("109-84", p.Image)
                imgImage.CssClass = "media-object"
                hplImage.NavigateUrl = MainDomain & "tin-tuc-chi-tiet/" & p.QueryString & "-" & p.Id & ".html"

                ltrDescription.Text = p.Description
                hplChiTiet.NavigateUrl = MainDomain & "tin-tuc-chi-tiet/" & p.QueryString & "-" & p.Id & ".html"

                '5 tin nho
                'Add DomainName DUC 09-09-2014
                'Dim p5 = (From q In Data.Contents Where q.Domain = DomainName And (q.Id <> p.Id) And q.StatusId = 3 _
                '          And q.PublishedDate <= Now() And (q.eEffectiveDate >= Now() Or q.eEffectiveDate Is Nothing)
                '          Order By q.PublishedDate Descending Select q).Take(10).ToList
                Dim p5 = (From q In Data.Contents Where q.Domain = DomainName And q.Id <> p.Id And q.StatusId = 3
                          Order By q.PublishedDate Descending Select q).Take(5).ToList

                With rptTinTuc
                    .DataSource = p5
                    .DataBind()
                End With
            End If
        End Using
    End Sub
    Protected Sub rptTinTuc_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptTinTuc.ItemDataBound
        Dim row As VSModel.Content = CType(e.Item.DataItem, VSModel.Content)
        Dim hplTitle As HyperLink = CType(e.Item.FindControl("hplTitle"), HyperLink)
        hplTitle.NavigateUrl = MainDomain & "tin-tuc-chi-tiet/" & row.QueryString & "-" & row.Id & ".html"
        Dim ltrTitle As Literal = CType(e.Item.FindControl("ltrTitle"), Literal)
        ltrTitle.Text = row.Title
        Dim ltrNgayDang As Literal = CType(e.Item.FindControl("ltrNgayDang"), Literal)
        ltrNgayDang.Text = row.PublishedDate
    End Sub
End Class
